<template>
  <div>
    <div class="div-top">
      <span>日志管理</span>
    </div>
    <div style="margin: 20px">
      <span class="topic-courselabel">时间：</span>
      <el-date-picker
        v-model="startEnd"
        value-format="yyyy-MM-dd HH:mm:ss"
        style="width: 380px;"
        type="datetimerange"
        range-separator="-"
        start-placeholder="开始日期"
        end-placeholder="结束日期"
      ></el-date-picker>
      <el-button type="primary" @click="search" style="margin-left: 5px"
        >搜索</el-button
      >
    </div>
    <div class="coursenav-body">
      <el-table :data="treeData" border style="width: 100%">
        <el-table-column align="center" prop="username" label="用户">
        </el-table-column>
        <el-table-column align="center" prop="operation" label="操作">
        </el-table-column>
        <el-table-column align="center" prop="ip" label="登录ip">
        </el-table-column>
        <!-- <el-table-column align='center' prop="address" label="地址">
				</el-table-column> -->
        <el-table-column align="center" prop="createDate" label="操作时间">
          <template slot-scope="scope">
            {{ scope.row.createDate | formatTimeLocal }}
          </template>
        </el-table-column>
      </el-table>
      <div style="width: 100%;margin: 15px;text-align: center;">
        <el-pagination
          background
          @current-change="handleCurrentChange"
          :current-page="page"
          layout="total,prev, pager, next, jumper"
          :total="totalRow"
        >
        </el-pagination>
      </div>
    </div>
  </div>
</template>

<script>
import { logList } from '@/api/logs'
export default {
  name: 'logs',
  data() {
    return {
      page: 1,
      pageSize: 10,
      totalRow: null,
      treeData: null,
      startEnd: null,
      stattime: null,
      endtime: null
    }
  },
  created() {
    this.getList()
  },
  mounted() {},
  methods: {
    search() {
      this.page = 1
      this.getList()
    },
    handleCurrentChange(page) {
      this.page = page
      this.getList()
    },
    getList() {
      var data = {
        current: this.page,
        size: this.pageSize
      }
      if (this.startEnd && this.startEnd.length == 2) {
        data.stattime = this.startEnd[0]
        data.endtime = this.startEnd[1]
      }
      logList(data).then(async res => {
        this.treeData = res.data.records
        this.totalRow = res.data.total
      })
    }
  }
}
</script>

<style></style>
